<template>
  <div class="app-container">
    <div style="margin-top: 20px">
      <svg-icon
        icon-class="marker"
        style="color: #606266"
      ></svg-icon>
      <span class="font-small">基本信息</span>
    </div>
    <div class="table-layout">
      <el-row>
        <el-col
          :span="6"
          class="table-cell-title"
        >课程名称</el-col>
        <el-col
          :span="6"
          class="table-cell-title"
        >类型</el-col>
        <el-col
          :span="12"
          class="table-cell-title"
        >来源机构</el-col>
      </el-row>
      <el-row>
        <el-col
          :span="6"
          class="table-cell"
        >{{ course.courseName }}</el-col>
        <el-col
          :span="6"
          class="table-cell"
        >{{ course.typeList | formatCouerseType }}</el-col>
        <el-col
          :span="12"
          class="table-cell"
        >{{ course.deptName }}</el-col>
      </el-row>
      <el-row>
        <el-col
          :span="6"
          class="table-cell-title"
        >最近更新</el-col>
        <el-col
          :span="6"
          class="table-cell-title"
        >更新频率</el-col>
        <el-col
          :span="12"
          class="table-cell-title"
        >简介</el-col>
      </el-row>
      <el-row>
        <el-col
          :span="6"
          class="table-cell"
          style="font-size: 13px"
        >{{ course.updateTime | formatDateTime }}</el-col>
        <el-col
          :span="6"
          class="table-cell"
        >{{ course.frequency }}</el-col>
        <el-col
          :span="12"
          class="table-cell"
        >
          <el-popover
            placement="top-start"
            trigger="hover"
            :content="course.courseDesc"
          >
            <span slot="reference">{{ course.courseDesc }}</span>
          </el-popover>
        </el-col>
      </el-row>
      <el-row>
        <el-col
          :span="6"
          class="table-cell-title"
        >录入时间</el-col>
        <el-col
          :span="6"
          class="table-cell-title"
        >视频数量</el-col>
        <el-col
          :span="6"
          class="table-cell-title"
        >讲师</el-col>
        <el-col
          :span="6"
          class="table-cell-title"
        >收藏数量</el-col>
      </el-row>
      <el-row>
        <el-col
          :span="6"
          class="table-cell"
          style="font-size: 13px"
        >{{ course.createTime | formatDateTime }}</el-col>
        <el-col
          :span="6"
          class="table-cell"
        >{{ course.videoCount }}</el-col>
        <el-col
          :span="6"
          class="table-cell"
        >{{ course.teacher }}</el-col>
        <el-col
          :span="6"
          class="table-cell"
        >{{ course.collectCount }}</el-col>
      </el-row>
    </div>
    <div style="margin-top: 20px">
      <svg-icon
        icon-class="marker"
        style="color: #606266"
      ></svg-icon>
      <span class="font-small">课程封面</span>
    </div>
    <img
      v-if="course.coursePic"
      class="coursePic"
      :src="course.coursePic"
    />
    <el-row
      type="flex"
      justify="end"
      style="margin-top: 20px"
    >
      <el-col :span="2">
        <el-button @click="back">返回</el-button>
      </el-col>
    </el-row>

  </div>
</template>
<script>
import { curCourseBaseGetById } from "@/api/course";
import { formatDate } from "@/utils/date";
export default {
  name: "CourseList",
  data() {
    return {
      course: {},
      list: null,
      total: null,
      listLoading: false,
    };
  },
  created() {
    curCourseBaseGetById({ id: this.$route.query.id }).then((response) => {
      this.course = response.data;
      console.log(this.course);
    });
  },
  filters: {
    formatCouerseType(typeList) {
      let type = "";
      typeList &&
        typeList.map((item, index) => {
          type = type + item.name + (typeList.length === index + 1 ? "" : "/");
        });
      return type;
    },
    formatDateTime(time) {
      if (time == null || time === "") {
        return "N/A";
      }
      const date = new Date(time);
      return formatDate(date, "yyyy-MM-dd hh:mm:ss");
    },
  },
  methods: {
    back() {
      this.$router.go(-1);
    },
  },
};
</script>
<style scoped>
.app-container {
  width: 80%;
  margin: 20px auto;
}

.table-layout {
  margin-top: 20px;
  border-left: 1px solid #dcdfe6;
  border-top: 1px solid #dcdfe6;
}

.table-cell {
  height: 60px;
  line-height: 40px;
  border-right: 1px solid #dcdfe6;
  border-bottom: 1px solid #dcdfe6;
  padding: 10px;
  font-size: 14px;
  color: #606266;
  text-align: center;
  overflow: hidden;
}

.table-cell-title {
  border-right: 1px solid #dcdfe6;
  border-bottom: 1px solid #dcdfe6;
  padding: 10px;
  background: #f2f6fc;
  text-align: center;
  font-size: 14px;
  color: #303133;
}

.coursePic {
  margin-top: 20px;
  max-width: 100%;
}
</style>
